package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.WorkCustomerMapper;
import com.ruoyi.system.domain.WorkCustomer;
import com.ruoyi.system.service.IWorkCustomerService;
import com.ruoyi.common.core.text.Convert;

/**
 * 用户Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-04-20
 */
@Service
public class WorkCustomerServiceImpl implements IWorkCustomerService 
{
    @Autowired
    private WorkCustomerMapper workCustomerMapper;

    /**
     * 查询用户
     * 
     * @param id 用户ID
     * @return 用户
     */
    @Override
    public WorkCustomer selectWorkCustomerById(Long id)
    {
        return workCustomerMapper.selectWorkCustomerById(id);
    }

    /**
     * 查询用户列表
     * 
     * @param workCustomer 用户
     * @return 用户
     */
    @Override
    public List<WorkCustomer> selectWorkCustomerList(WorkCustomer workCustomer)
    {
        List<WorkCustomer> workCustomers = workCustomerMapper.selectWorkCustomerList(workCustomer);
        ArrayList<WorkCustomer> workCustomers1 = new ArrayList<>();
        for (WorkCustomer customer : workCustomers) {
            if(customer.getStatus().equals("1")){
                workCustomers1.add(customer);
            }
        }
        return workCustomers1;
    }

    /**
     * 新增用户
     * 
     * @param workCustomer 用户
     * @return 结果
     */
    @Override
    public int insertWorkCustomer(WorkCustomer workCustomer)
    {
        String name = workCustomerMapper.selectWorkCustomerByName(workCustomer.getName());
        if (StringUtils.isNotEmpty(name)){
            workCustomer.setStatus("1");
            return workCustomerMapper.updateWorkCustomerByName(workCustomer);
        }
        return workCustomerMapper.insertWorkCustomer(workCustomer);
    }

    /**
     * 修改用户
     * 
     * @param workCustomer 用户
     * @return 结果
     */
    @Override
    public int updateWorkCustomer(WorkCustomer workCustomer)
    {
        return workCustomerMapper.updateWorkCustomer(workCustomer);
    }

    /**
     * 删除用户对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteWorkCustomerByIds(String ids)
    {
        return workCustomerMapper.deleteWorkCustomerByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除用户信息
     * 
     * @param id 用户ID
     * @return 结果
     */
    @Override
    public int deleteWorkCustomerById(Long id)
    {
        return workCustomerMapper.deleteWorkCustomerById(id);
    }

}
